package com.pearl.mybatis.demo;

import cn.hutool.core.bean.BeanUtil;
import cn.zhxu.bs.BeanSearcher;
import com.pearl.mybatis.demo.pojo.R;
import com.pearl.mybatis.demo.pojo.UserQueryParam;
import com.pearl.mybatis.demo.pojo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * -
 * -
 *
 * @author TangDan
 * @version 1.0
 * @since 2023/5/8
 */
@RestController
@RequestMapping()
public class TestController {

    @Autowired
    private BeanSearcher beanSearcher;              // 注入 BeanSearcher 的检索器

    @GetMapping("/index")
    public R<List<UserVO>> index(UserQueryParam param) {
        // 将 UserQueryParam 对象转换为 Map 再传入进行检索
        List<UserVO> userList = beanSearcher.searchList(UserVO.class, BeanUtil.beanToMap(param));
        return R.success(userList);
    }

/*    @GetMapping("/query")
    public R<UserVO> queryUser(UserQueryParam param) {
        // 根据请求参数构建查询条件
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>()
                .eq(StringUtils.isNotBlank(param.getUserName()), User::getUserName, param.getUserName())
                .gt(param.getState() != null, User::getState, param.getState());
        // 执行查询
        User user = userService.getOne(queryWrapper);
        // 对象转换并返回
        UserVO userVO = new UserVO();
        BeanUtils.copyProperties(user, userVO);
        return R.success(userVO);
    }*/
}
